package jungletimers;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;
import net.miginfocom.swing.MigLayout;

/**
 *
 * @author nmaludy
 */
public class TeamPanel extends JPanel {

    private static final long serialVersionUID = 1L;

    private final JLabel teamLabel;
    private final CreepTimerPanel blueTimer;
    private final CreepTimerPanel wolvesTimer;
    private final CreepTimerPanel wraithsTimer;
    private final CreepTimerPanel redTimer;
    private final CreepTimerPanel golemsTimer;

    public TeamPanel(String teamName, Timer timer) {
        super();
        this.teamLabel = new JLabel(teamName);
        this.blueTimer = CreepTimerPanelFactory.newBlueTimer();
        this.wolvesTimer = CreepTimerPanelFactory.newWolvesTimer();
        this.wraithsTimer = CreepTimerPanelFactory.newWraithsTimer();
        this.redTimer = CreepTimerPanelFactory.newRedTimer();
        this.golemsTimer = CreepTimerPanelFactory.newGolemsTimer();
        associateTimers(timer);
        layoutUi();
    }

    private void associateTimers(Timer timer) {
        timer.addActionListener(blueTimer);
        timer.addActionListener(wolvesTimer);
        timer.addActionListener(wraithsTimer);
        timer.addActionListener(redTimer);
        timer.addActionListener(golemsTimer);
    }

    private void layoutUi() {
        MigLayout ml = new MigLayout("insets 0 0 0 0", //Layout constraints
                "[fill]", //column constraints
                "[fill]"); //row constraints
        super.setLayout(ml);
        super.add(teamLabel, "grow, wrap");
        super.add(blueTimer, "grow, wrap");
        super.add(wolvesTimer, "grow, wrap");
        super.add(wraithsTimer, "grow, wrap");
        super.add(redTimer, "grow, wrap");
        super.add(golemsTimer, "grow");
    }

    public void resetTimers() {
        this.blueTimer.reset();
        this.wolvesTimer.reset();
        this.wraithsTimer.reset();
        this.redTimer.reset();
        this.golemsTimer.reset();
    }
}
